package day06;

import java.util.Scanner;

public class CalAvg {
    public static void main(String[] args) {//撒贝宁
        double[] scores = inputData(6);//1)录入评委的评分
        double avg =calAvg(scores);//2)计算平均分
        System.out.println("平均分为:"+avg);
    }
    //该方法用于录入N位评委的评分
    public static double[] inputData(int n){
        double[] scores = new double[n];//评分数组
        Scanner scan = new Scanner(System.in);
        for (int i=0;i<scores.length;i++){
            System.out.println("请录入第"+(i+1)+"位评委的分数:");
            scores[i]=scan.nextDouble();
        }
        return scores;
    }
    //该方法用于计算平均分
    public static double calAvg(double[] scores){
        double sum =0.0;
        double max = scores[0];
        double min = scores[0];
        for (int i=0;i<scores.length;i++){
            sum+=scores[i];
            if (max>scores[i]){
                max=scores[i];
            }
            if(min<scores[i]){
                min=scores[i];
            }
        }
        double avg =(sum-max-min)/(scores.length-2);//平均分
        return avg;
    }
}
